﻿using System;
using HigLabo.Net.Extensions;

namespace HigLabo.Net.WindowsLive
{
    /// <summary>
    /// 
    /// </summary>
    public class Contact : ResponseObject
    {
        /// <summary>
        /// 
        /// </summary>
        public String ID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String FirstName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String LastName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Gender { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean IsFriend { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean IsFavorite { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String UserId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public ContactEmailHashes EmailHashes { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 BirthDay { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 BirthMonth { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTimeOffset? UpdatedTime { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public Contact(String jsonText)
        {
            this.SetProperty(jsonText);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public override void SetProperty(String jsonText)
        {
            var d = this.SetData(jsonText);
            this.ID = d.ToString("id");
            this.FirstName = d.ToString("first_name");
            this.LastName = d.ToString("last_name");
            this.Name = d.ToString("name");
            this.Gender = d.ToString("gender");
            this.IsFriend = d.ToBoolean("is_friend") ?? false;
            this.IsFavorite = d.ToBoolean("is_favorite") ?? false;
            this.UserId = d.ToString("user_id");
            this.EmailHashes = new ContactEmailHashes(d.ToString("email_hashes"));
            if (!HttpClient.IsNullOrWhiteSpace(d.ToString("birth_day")))
                this.BirthDay = d.ToInt32("birth_day") ?? 0;
            if (!HttpClient.IsNullOrWhiteSpace(d.ToString("birth_month")))
                this.BirthMonth = d.ToInt32("birth_month") ?? 0;
            this.UpdatedTime = d.ToDateTimeOffset("updated_time");
        }
    }
}
